﻿using System.Collections;

namespace Dark_Core_Server.Models.Universal
{
    public static class UniversalHelper
    {
        /// <summary>
        /// 转换为数据组回复
        /// </summary>
        /// <typeparam name="S">数据源类型</typeparam>
        /// <param name="dataArr">数据数组</param>
        /// <param name="total">条目</param>
        /// <returns></returns>
        public static DataArrResponse<S> ToDataArrResponse<S>(this List<S> dataArr, long total) => new DataArrResponse<S>(total, dataArr);

        /// <summary>
        /// 转换为数据组回复
        /// </summary>
        /// <typeparam name="S">数据源类型</typeparam>
        /// <param name="dataArr">数据数组</param>
        /// <returns></returns>
        public static DataArrResponse<S> ToDataArrResponse<S>(this List<S> dataArr) => new DataArrResponse<S>(dataArr.Count, dataArr);
        /// <summary>
        /// 转换为数据组回复
        /// </summary>
        /// <typeparam name="S">数据源类型</typeparam>
        /// <param name="dataArr">数据数组</param>
        /// <returns></returns>
        public static DataArrResponse<S> ToDataArrResponse<S>(this S[] dataArr) => new DataArrResponse<S>(dataArr.Length, dataArr.ToList());
    }
}
